﻿using UnityEngine;
using System.Collections;

public class FirstPersonController : MonoBehaviour 
{
	//player movement speed
	public float movementSpeed = 5.0f;
	//character controller create
	public CharacterController cc;
	//variable for forward speed
	float forwardSpeed;
	//variable for side speed
	float sideSpeed;
	//variable for rotation
	float rotateLeftRight;
	//vector variable for directional movement
	Vector3 speed;
	

	// Use this for initialization
	void Start () 
	{
	
	}
	
	// Update is called once per frame
	void Update () 
	{
		rotateLeftRight = Input.GetAxis("Mouse X");
		transform.Rotate(0, rotateLeftRight, 0);

		forwardSpeed = Input.GetAxis("Vertical") * movementSpeed;
		sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;

		speed = new Vector3(sideSpeed,0,forwardSpeed);
		//modifying movement with rotation
		speed = transform.rotation * speed;


		cc = GetComponent<CharacterController>();
		cc.SimpleMove(speed);
	}
}
